Fortran 通用转译器:概念验证
文章背景与核心概要
Fortran 长期以来一直是高性能计算(HPC)的基石,在许多领域依然无可匹敌。然而,该语言面临着严重的人才断层:新一代科学家对 Fortran 知之甚少,而许多经验丰富的 Fortran 开发者才刚刚开始向 JAX 等现代生态系统过渡。这种断层通常会导致“Fython”(即带有 Fortran 思维的 Python 代码)的产生,从而无法充分利用现代框架的优势。
为了应对这一挑战,本文提出了 FGPT(Fortran通用转译器)框架。它提供了一个系统化的处理流水线,能够将 Fortran 代码转译为适配 GPU 的 Fortran、通过 Tapenade 实现自动微分的 Fortran,或者 NumPy 与 JAX 脚本。FGPT 包含前端解析、中端转换和后端优化三个核心阶段,在保持程序语义的同时,成功在气候建模核心算例上实现了无需人工干预的正确且可微的 Python 实现转换,为现代化遗留 Fortran 代码提供了一条可扩展且值得信赖的路径。
概述与元数据
- arXiv ID: arXiv:2608.00130 [cs.PL]
- 学科分类: 编程语言 (
cs.PL); 人工智能 (cs.AI); 计算与语言 (cs.CL); 数学软件 (cs.MS); 软件工程 (cs.SE) - 作者: Shivamshan Sivanesan, Kazem Ardaneh
- 提交时间: 2026年7月31日 (v1); 最近修订 2026年8月6日 (v2)
- 开源许可: 知识共享 署名-非商业性使用-相同方式共享 4.0 国际版 (
查看许可证)
Overview & Metadata
- arXiv ID: arXiv:2608.00130 [cs.PL]
- Subjects: Programming Languages (
cs.PL); Artificial Intelligence (cs.AI); Computation and Language (cs.CL); Mathematical Software (cs.MS); Software Engineering (cs.SE)- Authors: Shivamshan Sivanesan, Kazem Ardaneh
- Submitted: July 31, 2026 (v1); Last revised August 6, 2026 (v2)
- License: Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International (
view license)
摘要
Fortran 长期以来一直是高性能计算的基石,在许多领域依然无可匹敌。然而,该语言面临着严重的人才断层:新一代科学家对 Fortran 知之甚少,而许多经验丰富的 Fortran 开发者才刚刚开始向 JAX 等现代生态系统过渡。这种断层通常会导致“Fython”(即带有 Fortran 思维的 Python 代码)的产生,从而无法充分利用现代框架的优势。
我们提出了 FGPT,这是一个旨在弥合这一鸿沟的转译器框架。它提供了一个系统化的流水线,能够将 Fortran 转译为适配 GPU 的 Fortran、通过 Tapenade 实现自动微分的 Fortran,或是 NumPy 与 JAX 脚本。
架构
FGPT 的架构包含三个主要阶段: 1. 前端 (Frontend): 解析 Fortran 代码,并提取目标过程及其所有依赖项。 2. 中端 (Middle-end): 将代码降级(Lower)为中间表示(IR),随后将其转换为适配 GPU 的 Fortran、可自动微分的 Fortran 或 NumPy 类。 3. 后端 (Backend): 将 NumPy 脚本转换为针对 GPU 加速和自动微分进行过优化的 JAX 模块。
核心贡献与验证
当大语言模型被应用于规模庞大(通常跨越数十万行代码)的社区科学代码时,往往会由于需要保持一致的转换、严格的数值保真度以及通过生产环境测试的验证而失败。FGPT 通过在整个翻译流水线中保持程序语义来解决这些挑战。
该框架已在具有代表性的气候建模内核上得到验证,在无需人工干预的情况下成功生成了正确且可微的 Python 实现。通过将严谨的编译器技术与现代加速器支持相结合,FGPT 为现代化遗留 Fortran 代码提供了一条可扩展且值得信赖的路径。
Abstract
Fortran has been the cornerstone of high-performance computing for decades and remains unmatched in many domains. Yet the language faces an expertise gap: a new generation of scientists is barely familiar with it, while many experienced Fortran developers are only now transitioning to modern ecosystems such as JAX. This gap often results in "Fython" — Python code written with a Fortran mindset — that fails to leverage modern frameworks.
We present FGPT, a transpiler framework designed to bridge this gap. It provides a systematic pipeline that transpiles Fortran into GPU-adapted Fortran, auto-differentiable Fortran via Tapenade, or NumPy and JAX scripts.
Architecture
FGPT's architecture comprises three primary stages: 1. Frontend: Parses Fortran code and extracts target procedures along with all their dependencies. 2. Middle-end: Lowers the code into an intermediate representation, then transforms it into GPU-adapted Fortran, auto-differentiable Fortran, or a NumPy class. 3. Backend: Transforms NumPy scripts into JAX modules optimized for GPU acceleration and automatic differentiation.
Key Contributions & Verification
Large language models often fail when applied to the scale of community scientific codes—which frequently span hundreds of thousands of lines—due to the need for consistent transformations, strict numerical fidelity, and validation against production tests. FGPT addresses these challenges by preserving program semantics throughout the entire translation pipeline.
The framework has been verified on representative climate modeling kernels, successfully producing correct, differentiable Python implementations without requiring manual intervention. By combining rigorous compiler techniques with modern accelerator support, FGPT offers a scalable, trustworthy path for modernizing legacy Fortran code.
访问与资源
- 全文链接: 查看 PDF | HTML (实验性) | TeX 源码
- 引用与参考: NASA ADS | Google 学术 | Semantic Scholar
Access & Resources
- Full-Text Links: View PDF | HTML (Experimental) | TeX Source
- Citations & References: NASA ADS | Google Scholar | Semantic Scholar